//
//  QKCoreAnimation.m
//  testTool
//
//  Created by qiankun on 2019/7/24.
//  Copyright © 2019 com.qiankun. All rights reserved.
//

#import "QKCoreAnimation.h"

@interface QKCoreAnimation()
{
    int _i;
}

@end

@implementation QKCoreAnimation

-(void)test3DTrans
{
    _i = 0;
    
    self.testView = nil;
    [self.testView removeFromSuperview];
    
    self.testView = [UIImageView new];
    self.testView.image = [UIImage imageNamed:@"IMG_2523"];
    self.testView.layer.contentsRect = CGRectMake(0, 0, 1, 0.5);
    
    UIImageView *tempImg = [UIImageView new];
    tempImg.image = [UIImage imageNamed:@"IMG_2523"];
    tempImg.layer.contentsRect = CGRectMake(0, 0.5, 1, 0.5);
    
    
    
    
    [self.view addSubview:self.testView];
    [self.view addSubview:tempImg];
    
    
    
    
    [self.testView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.centerY.mas_equalTo(self.view);
        make.height.mas_equalTo(204);
        make.width.mas_equalTo(204);
    }];
    
    [tempImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.testView.mas_bottom);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(204);
        make.width.mas_equalTo(204);
    }];
    
    
}



-(void)testCABasicAnimAation{
    //CABasicAnimation 基础动画
    
    CABasicAnimation *position = [CABasicAnimation animationWithKeyPath:@"position.y"];
    position.fromValue = @(self.testView.center.y);
    position.toValue = @(self.testView.center.y - 30);
    
    CABasicAnimation *transformAnima = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
    transformAnima.fromValue = @(0);
    transformAnima.toValue = @(M_PI);
    
    CAAnimationGroup *anim  = [CAAnimationGroup animation];
    anim.removedOnCompletion = NO;
    anim.fillMode = @"forwards";
    anim.animations = @[position,transformAnima];
}

-(void)testHeartJumpAnim{
    
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    anim.toValue = @0;
    anim.repeatCount = MAXFLOAT;
    anim.duration = 1.0;
    anim.autoreverses = YES;
    [self.testView.layer addAnimation:anim forKey:@"A"];
}
//CAKeyframeAnimation
-(void)TestCAKeyframeAnimation{
    //CAKeyframeAnimation 基础动画
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    // 指定 path
    UIBezierPath *path = [[UIBezierPath alloc] init];
    [path moveToPoint:CGPointMake(120, 120)];
    [path addLineToPoint:CGPointMake(300, 120)];
    [path addLineToPoint:CGPointMake(300, 340)];
    anim.duration = 2;
    anim.path = path.CGPath;
    
    //  指定values
    //    anim.duration = 1;
    //    anim.values = @[@(angle2Rad(-5)),@(angle2Rad(5))];
    //    anim.repeatCount = MAXFLOAT;
    //    anim.autoreverses = YES;
    [self.testView.layer addAnimation:anim forKey:nil];
}
//转场动画
-(void)CATransitionAnimation
{
    
    //    NSArray *arr = [NSArray arrayWithObjects:@"fade",@"moveIn",@"push", @"reveal", nil];
    //    _i ++;
    //    if (_i == 4) {_i = 1;}
    //    self.testView.image = [UIImage imageNamed:[NSString stringWithFormat:@"0%d",_i]];
    //    CATransition *transition = [CATransition animation];
    //    transition.duration = 1;
    //    transition.type = @"cameraIrisHollow";
    //    [self.testView.layer addAnimation:transition forKey:@"Anim"];
    
    CATransition *transition = [CATransition animation];
    transition.duration = 1;
    transition.type = @"cameraIrisHollow";
    transition.subtype = @"alignedCube";
    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
    [self.view.layer addAnimation:transition forKey:@"Anim"];
    
    UIViewController *two = UIViewController.new;
    two.view.backgroundColor = UIColor.redColor;
//    [self.navigationController pushViewController:two animated:YES];
//    [self.navigationController.view.layer addAnimation:transition forKey:@"anim"];
    
}

@end
